package me.ywd.eureka.client.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * getNextServerFromEureka的参数我试了hostName，serviceId......
 * 很久之后才发现时serviceId要大写。
 *
 * @Author Ye_Wenda
 * @Date 9/7/2017
 */
@RestController
@RequestMapping("native")
public class NativeDemoController {

    @Autowired
    private EurekaClient eurekaClient;

    @Autowired
    private ObjectMapper objectMapper;

    @GetMapping("instance")
    public String instance() throws JsonProcessingException {
        InstanceInfo instance = eurekaClient.getNextServerFromEureka("EUREKA-CLIENT", false);
        return objectMapper.writeValueAsString(instance);
    }
}
